package com.weetop.cfw.base.presenter.imp

import android.os.Message
import com.weetop.cfw.base.presenter.MessageDetailPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.MessageDetailView
import com.weetop.cfw.bean.MessageDetailBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.message.activity.MessageDetailActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class MessageDetailPresenterImp(var messageDetailView: MessageDetailView? = null):MessageDetailPresenter {


    /**
     * 消息详情
     */
    override fun getMessageDetailData(messageDetailActivity: MessageDetailActivity, messageId: Int) {
        messageDetailActivity.showLoadingDialog(messageDetailActivity,"正在获取消息详情...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getMessageDetailData(msgid = messageId),messageDetailActivity,object:RxJavaCallBack<MessageDetailBean>(){
            override fun onSuccess(t: MessageDetailBean?) {
                messageDetailActivity.dismissLoadingDialog()
                messageDetailView?.getMessageDetailDataSuccess(t)
            }

            override fun onRequestError(t: MessageDetailBean?) {
                super.onRequestError(t)
                messageDetailActivity.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                messageDetailActivity.dismissLoadingDialog()
            }
        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        messageDetailView = baseView as? MessageDetailView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        messageDetailView = null
    }
}